package com.study.leetcode;

public class Solution_111 {
    private int min = Integer.MAX_VALUE;

    public int minDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        minDepth(root, 1);
        return min;
    }

    public void minDepth(TreeNode root, int deep) {

        if (root.left == null && root.right == null) {
            if (deep < min) {
                min = deep;
            }
            return;
        }
        if (root.left != null) {
            minDepth(root.left, deep + 1);
        }
        if (root.right != null) {
            minDepth(root.right, deep + 1);
        }
    }

    public static void main(String[] args) {

    }
}
